import userTempIdno from "@/utils/usertmpltemid";
import { getItem, setItem, removeItem } from "@/utils/localstorage";
import {
  reqLogin, reqUserMessage
} from "@/api";

const state = {
  userTempId: userTempIdno(),
  token: getItem("token") || '',
  userMessage: {}
};
const mutations = {
  set_token(state, payload) {
    state.token = payload.token;
    setItem('token', payload.token);
  },

  set_userMessage(state, payload) {
    state.userMessage = payload.Message;
  },
  remove_token(state) {
    state.token = "";
    removeItem("token");
  }
};
const actions = {

  async get_token({ commit }, userInfo) {
    const result = await reqLogin(userInfo);
    commit("set_token", { token: result.token });
  },

  async get_userMessage({ commit }) {
    const result = await reqUserMessage();
    commit("set_userMessage", { Message: result });
  }
};
const getters = {};
export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
};